

export default abstract class FrameComponent extends cc.Component {
    /**
     * 组件入口
     */
    public abstract onShow(data?: any): Promise<void>;

    // 组件渲染后
    protected async onShowEnd(data?: any): Promise<void> { return Promise.resolve(); }

    // 参数
    public args: Array<any> = [];

    protected async onEnable() {
        //注册监听

        //给节点下所有按钮添加点击音效
        let buttons = this.node.getComponentsInChildren(cc.Button);
        for (let i = 0; i < buttons.length; ++i) {
            let flag = false;
            for (let j = 0; j < buttons[i].clickEvents.length; ++j) {
                if (buttons[i].clickEvents[j].handler == "onClickVoice") {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                continue;
            }
            const eventHandler = new cc.Component.EventHandler();
            eventHandler.target = this.node;

            eventHandler.component = this.node.name;

            eventHandler.handler = "onClickVoice";
            buttons[i].clickEvents.push(eventHandler);
        }

        this.onShow(...this.args);
        this.onShowEnd(...this.args);
    }
}